import {request} from "@/plugins/request"

// 获取公共的文章列表
export const getArticles = params => {
  return request({
    method: "GET",
    url: "/api/articles",
    params
  })
}

// 获取公共的文章列表
export const getYourFeedArticles = params => {
  return request({
    method: "GET",
    url: "/api/articles/feed",
    params,
    // headers: {
    //   // 添加用户身份。注意Token与数据之间有一个空格
    //   Authorization: `Token eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6MTExMjA2LCJ1c2VybmFtZSI6Ik1DQ01BTiIsImV4cCI6MTYwMzQ1NTY0OX0.XINQ0mDfxx7OSXfrmVVGZ3ybqDcTQAVjK5FKPgRyTQ0`
    // }
  })
}

// 添加点赞
export const addFavorite = slug => {
  return request({
    method: "POST",
    url: `/api/articles/${slug}/favorite`
  })
}

// 取消点赞
export const deleteFavorite = slug => {
  return request({
    method: "DELETE",
    url: `/api/articles/${slug}/favorite`
  })
}

// 获取文章详情
export const getArticle = slug => {
  return request({
    method: "GET",
    url: `/api/articles/${slug}`
  })
}

// 获取文章平评论
export const getComments = slug => {
  return request({
    method: "GET",
    url: `/api/articles/${slug}/comments`
  })
}